import java.util.Scanner;

/**
 * @author vivi
 * @description
 * @date 2024/5/25
 */
public class demo3 {
    public static void main (String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        char[] s = in.next().toCharArray();
        long[] f = new long[26];
        long[] g = new long[26];
        long ret = 0;
        for(int i = 0; i < n; i++) {
            int x = s[i] - 'a';
            ret += f[x];
            // 更新哈希表
            f[x] = f[x] + i - g[x];
            g[x] = g[x] + 1;
        }
        System.out.println(ret);
    }
}
